﻿//var grid = mini.get("datagrid1");
//grid.setUrl();
//grid.reload();

///绑定下拉列表
$(document).ready(function () {
    fnDataGridDataBing("datagrid1","/extendpage/data/jsondata.aspx?entity=t_sys_function_operation&order=sort&condition=function_id='" + instance.id + "'")
});

function fnOpAdd() {
    var grid = mini.get("datagrid1");
    var newRow = { "id": "", "function_id": instance.id };
    grid.addRow(newRow, 0);
}

function fnOpRemove() {
    var grid = mini.get("datagrid1");
    var rows = grid.getSelecteds();
    if (rows.length > 0) {
        grid.removeRows(rows, true);
        $.each(rows, function (i) {
            //edit.common.js的通用方法
            fnFormRemove("t_sys_function_operation","id",rows[i].id);
        });
    }
}

function fnCustomSave() {
    var form = new mini.Form("#form1");
    form.validate();
    if (!form.isValid()) return;
    var form_data = form.getData();
    fnClone(form_data, instance);
    if (typeof (instance) != "undefined" && instance != null) {
        var msg = mini.loading("数据保存中，请稍后......", "系统消息提醒");
        var json = mini.encode(instance);   //序列化成JSON
        var grid = mini.get("datagrid1");
        var data = grid.getChanges();
        var json2 = mini.encode(data);
        json = json + "[@@@]" + json2;
        var _rData = mini.encode(_removeData);
        $.ajax({
            url: "/extendpage/action/mdatasave.aspx?entity=t_sys_function:t_sys_function_operation&flag=1&action=mutibatchsave",
            type: "post",
            data: { data: json, removeData: _rData },
            cache: false,
            success: function (text) {
                if (text == 1) {
                    alert("数据保存成功!")
                    fnClose();
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
        mini.hideMessageBox(msg);
    }
}